﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.Process;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week1.Process_CRUD
{
    /// <summary>
    /// 显示工序表数据
    /// </summary>
    public class ShowProcessHandler : IRequestHandler<ShowProcessCommand, Result>
    {
        public ShowProcessHandler(IBaseRepository<Process> processRepository)
        {
            ProcessRepository = processRepository;
        }

        public IBaseRepository<Process> ProcessRepository { get; set; }

        public async Task<Result> Handle(ShowProcessCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCodes.Search};
            var sql = "select * from Process;";
            var list = ProcessRepository.GetAll(sql);
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCodes.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
